/*padStart方法兼容ie*/
if (!String.prototype.padStart) {
    String.prototype.padStart = function padStart(targetLength,padString) {
        targetLength = targetLength>>0; //truncate if number or convert non-number to 0;
        padString = String((typeof padString !== 'undefined' ? padString : ' '));
        if (this.length > targetLength) {
            return String(this);
        }
        else {
            targetLength = targetLength-this.length;
            if (targetLength > padString.length) {
                padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
            }
            return padString.slice(0,targetLength) + String(this);
        }
    };
}

/*通用错误处理方式*/
function showErr(msg, status) {
	if(status=="1000000"){
		var confirmTxt="点击登录";
	}else{
		var confirmTxt="关闭";
	}
	var curPath = window.location.href;
	if(curPath.indexOf("login.html") == -1) {
		top.alert("", msg, function() {
			if(status == '1000000') { //status为1000000,代表未登录
				// parent.window.location.href = location.origin + "/login.html";
				window.location.href = host_url + "admin/login.html";
			}
		}, {
			type: 'warning',
			confirmButtonText: confirmTxt
		});
	}
}

/* 取url中参数 */
function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}

// 格式化时间方法
function dateFormat(fmt, date) {
    var ret;
    var opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (var k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}
$(document).ready(function(){
	//退出登录
	$("#logout_a").on("click", function() {
		top.confirm("您确定要退出吗", "", function(isConfirm) {
			if(isConfirm) {
				$.ajax({
					type: "GET",
					url: service_url + "/a/zklogout", //请求地址
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					contentType: 'application/json',
					dataType: 'jsonp',
					jsonpCallback:"success_jsonpCallback",  
					processData: false, // 告诉jQuery不要去处理发送的数据
					headers: {
						"Authorization": $.cookie('Authorization')
					},
					success: function(data) {
						if(data.success) {
							window.location.href = host_url + "admin/login.html";
							// ************************** 网脉嵌码第三部分 start **********************************
							try{
								window.TA17Obj.clearLoginUser();//注销登录后调用
							}catch(e){
								//记录错误信息
							}
							// ************************** 网脉嵌码第三部分 end **********************************
						} else {
							top.alert("退出登录异常", {
								type: 'warning'
							});
						}

					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						console.log(errorThrown);
					}
				})
			} else {
				//after click the cancel
			}
		}, {
			confirmButtonText: '确定',
			cancelButtonText: '取消',
			width: 400
		});

	})
	
	/*加载公共footer*/
	$('#footer').load("footeroutline.html");
})

function showLoading (){
	$('#loadingModal').modal({backdrop: 'static', keyboard: false});
}

function hideLoading(){
	$('#loadingModal').modal('hide');
}